<template>
    <!-- 数据中心/财务数据中心/仓库周报数据采集 -->
    <div class="incomeExpend">
        <div class="top_operation">
            <!-- 顶部四级联动选择器联动组件 -->
            <TopSelect
                ref="topSelect"
                @headChange="getHeadId"
                :isRegionShow="isRegionShow"
                @regionChange="getRegionId"
                :isCityShow="isCityShow"
                @cityChange="getCityId"
                :isWareShow="isWareShow"
                @wareChange="getWareId"
            ></TopSelect>
            
            <div class="every_operation">
                <span>记账归属：</span>
                <a-range-picker
                    v-model="billTimeSearch"
                    format="YYYY-MM-DD HH:mm:ss"
                    :placeholder="['Start Time', 'End Time']"
                    @change="billTimeChange"
                    @ok="billTimeOk"
                    style="width:195px;"
                    :show-time="{
                        format: 'HH:mm:ss',
                        defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
                    }"
                />
            </div>

            <div class="button_div">
                <a-button type="primary" icon="search" @click="onSearch()">搜索</a-button>
                <a-button type="primary" icon="sync" style="margin-left:20px;" @click="onReset()">重置</a-button>
            </div>
        </div>
        
        <div class="add_btn">
            <!-- <a-button type="primary" @click="showDrawer">新增</a-button> -->
            <a-dropdown>
                <a-menu slot="overlay" @click="handleMenuClick">
                    <a-menu-item key="YY">
                        运营数据采集
                    </a-menu-item>
                    <a-menu-item key="CW">
                        财务数据采集
                    </a-menu-item>
                </a-menu>
                <a-button type="primary" style="width:82px;">新增<a-icon type="down" /> </a-button>
            </a-dropdown>
            <a-button style="margin-left:20px;" @click="batchDelete()">删除</a-button>
            <!-- 右滑抽屉 -->
            <a-drawer
                :maskClosable="false"
                :title="drawerTitle"
                :placement="placement"
                :closable="false"
                :visible="visible"
                @close="onClose"
                width="1000"
            >
                <a-form-model
                    ref="ruleForm"
                    :model="form"
                    :rules="rules"
                    :label-col="labelCol"
                    :wrapper-col="wrapperCol"
                    labelAlign="right"
                >

                    <span style="display: flex; flex-wrap: wrap">
                        <a-form-model-item style="width: 50%" ref="tocOrderExpressCost" prop="tocOrderExpressCost" v-if="this.key == 'YY'">
                            <span slot="label">
                                <a-popover>
                                    <template slot="content">
                                    <p style="margin:0">1.含物流2.用户以周为单位进行填写</p>
                                    </template>
                                    <img src="../../../assets/help_yellow.png" alt="" />
                                </a-popover>
                                <span> 2C单均快递成本(元)</span>
                            </span>
                            <a-input-number
                                id="areaNumber"
                                v-model="form.tocOrderExpressCost"
                                :precision="precision"
                                :min="0"
                                :max="2147483647"
                                style="width:100%;"
                                placeholder="请输入2C单均快递成本"
                                @blur="
                                    () => {
                                    $refs.tocOrderExpressCost.onFieldBlur()
                                    }
                                "
                            />
                        </a-form-model-item>

                        <a-form-model-item style="width: 50%" ref="laborCost" prop="laborCost" v-if="this.key == 'YY'">
                            <span slot="label">
                            <a-popover>
                                <template slot="content">
                                <p style="margin:0">1.人工成本含临时工、外包工，不含管理；2.用户以周为单位进行填写。</p>
                                </template>
                                <img src="../../../assets/help_yellow.png" alt="" />
                            </a-popover>
                            <span> 人工成本(元)</span>
                            </span>

                            <a-input-number
                                id="areaNumber"
                                v-model="form.laborCost"
                                :precision="precision"
                                :min="0"
                                :max="2147483647"
                                style="width:100%;"
                                placeholder="请输入人工成本"
                                @blur="
                                    () => {
                                    $refs.laborCost.onFieldBlur()
                                    }
                                "
                            />
                        </a-form-model-item>

                        <a-form-model-item style="width: 50%" ref="otherVariableCost" prop="otherVariableCost" v-if="this.key == 'YY'">
                            <span slot="label">
                            <a-popover>
                                <template slot="content">
                                <p style="margin:0">1.含包材（按消耗算）、罚款、意外支出、耗材、作业外包费用等2.用户以周为单位进行填写</p>
                                </template>
                                <img src="../../../assets/help_yellow.png" alt="" />
                            </a-popover>
                            <span> 其他变动成本(元)</span>
                            </span>

                            <a-input-number
                                id="areaNumber"
                                v-model="form.otherVariableCost"
                                :precision="precision"
                                :min="0"
                                :max="2147483647"
                                style="width:100%;"
                                placeholder="请输入其他变动成本"
                                @blur="
                                    () => {
                                    $refs.otherVariableCost.onFieldBlur()
                                    }
                                "
                            />
                        </a-form-model-item>

                        <a-form-model-item style="width: 50%" ref="managementCost" prop="managementCost" v-if="this.key == 'YY'">
                            <span slot="label">
                            <a-popover>
                                <template slot="content">
                                <p style="margin:0">1.全仓固定的管理团队薪资福利成本；2.用户以周为单位进行填写。</p>
                                </template>
                                <img src="../../../assets/help_yellow.png" alt="" />
                            </a-popover>
                            <span> 管理成本(元)</span>
                            </span>

                            <a-input-number
                                id="areaNumber"
                                v-model="form.managementCost"
                                :precision="precision"
                                :min="0"
                                :max="2147483647"
                                style="width:100%;"
                                placeholder="请输入管理成本"
                                @blur="
                                    () => {
                                    $refs.managementCost.onFieldBlur()
                                    }
                                "
                            />
                        </a-form-model-item>

                        <a-form-model-item style="width: 50%" ref="otherFixedCost" prop="otherFixedCost" v-if="this.key == 'YY'">
                            <span slot="label">
                            <a-popover>
                                <template slot="content">
                                <p style="margin:0">1.含利息支出、维修支出、消防支出、宿舍租金、仓库保险、打印办公费用、托盘、叉车租金等2.用户以周为单位进行填写</p>
                                </template>
                                <img src="../../../assets/help_yellow.png" alt="" />
                            </a-popover>
                            <span> 其他固定成本(元)</span>
                            </span>

                            <a-input-number
                                id="areaNumber"
                                v-model="form.otherFixedCost"
                                :precision="precision"
                                :min="0"
                                :max="2147483647"
                                style="width:100%;"
                                placeholder="请输入其他固定成本"
                                @blur="
                                    () => {
                                    $refs.otherFixedCost.onFieldBlur()
                                    }
                                "
                            />
                        </a-form-model-item>

                        <a-form-model-item style="width: 50%" ref="investmentCost" prop="investmentCost" v-if="this.key == 'CW'">
                            <span slot="label">
                            <a-popover>
                                <template slot="content">
                                <p style="margin:0">1.含招商费、线索费、不含业务招待报销；2.用户以周为单位进行填写。</p>
                                </template>
                                <img src="../../../assets/help_yellow.png" alt="" />
                            </a-popover>
                            <span> 招商成本(元)</span>
                            </span>

                            <a-input-number
                                id="areaNumber"
                                v-model="form.investmentCost"
                                :precision="precision"
                                :min="0"
                                :max="2147483647"
                                style="width:100%;"
                                placeholder="请输入招商成本"
                                @blur="
                                    () => {
                                    $refs.investmentCost.onFieldBlur()
                                    }
                                "
                            />
                        </a-form-model-item>

                        <a-form-model-item style="width: 50%" ref="managerSalary" prop="managerSalary" v-if="this.key == 'CW'">
                            <span slot="label">
                            <a-popover>
                                <template slot="content">
                                <p style="margin:0">1.用户以周为单位进行填写。</p>
                                </template>
                                <img src="../../../assets/help_yellow.png" alt="" />
                            </a-popover>
                            <span> 仓老板工资(元)</span>
                            </span>

                            <a-input-number
                                id="areaNumber"
                                v-model="form.managerSalary"
                                :precision="precision"
                                :min="0"
                                :max="2147483647"
                                style="width:100%;"
                                placeholder="请输入仓老板工资"
                                @blur="
                                    () => {
                                    $refs.managerSalary.onFieldBlur()
                                    }
                                "
                            />
                        </a-form-model-item>

                        <a-form-model-item style="width: 50%" ref="billTime" prop="billTime">
                            <span slot="label">
                            <a-popover>
                                <template slot="content">
                                <p style="margin:0">记账归属系统自动取当前一周的时间即开始时间取周六的00：00：00，结束时间取下一周周五的23：59：59</p>
                                </template>
                                <img src="../../../assets/help_yellow.png" alt="" />
                            </a-popover>
                            <span> 记账归属</span>
                            </span>
                            <!-- :show-time="{
                                format: 'HH:mm:ss',
                                defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
                            }" -->
                            <a-range-picker
                            v-model="form.billTime"
                            disabled
                            format="YYYY-MM-DD"
                            :placeholder="['Start Time', 'End Time']"
                            style="width:100%;"
                            :value="form.billTime"
                            @blur="
                                () => {
                                $refs.billTime.onFieldBlur()
                                }
                            "
                            />
                        </a-form-model-item>

                    </span>
                    
                    <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
                        <a-button type="primary" @click="onSubmit">
                            确定
                        </a-button>
                        <a-button style="margin-left: 10px;" @click="cancelForm">
                            取消
                        </a-button>
                    </a-form-model-item>
                </a-form-model>
            </a-drawer>
        </div>

        <div class="select_number">
            <span class="number_span">已选择<b>{{selectNumber}}</b>项</span>
            <span class="clear_span" @click="clearSelect">清空</span>
        </div>
        
        <div class="data_source_list">
            <div class="data_source_details">
                <a-table
                    :loading="tableLoading"
                    :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" 
                    :columns="columns" 
                    :data-source="data"
                    :pagination="false"
                    bordered
                    rowKey="id"
                    >
                    <span slot="billTime" slot-scope="text, record">
                        <a-tooltip placement="top">
                            <template slot="title">
                                <span>{{ `${record.billTimeBegin} - ${record.billTimeEnd}` }}</span>
                            </template>
                            <span>{{ `${record.billTimeBegin} - ${record.billTimeEnd}` }}</span>
                        </a-tooltip>
                        <!-- <span>{{ `${record.billTimeBegin}-${record.billTimeEnd}` }}</span> -->
                    </span>

                    <a slot="action" slot-scope="text, record" href="javascript:;">
                        <span v-if="setBtn(record)">
                            <a-dropdown style="margin-right:10px;">
                                <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                                修改<a-icon type="down" />
                                </a>
                                <a-menu slot="overlay">
                                    <a-menu-item>
                                        <a href="javascript:;" @click="doEditOperation(record)">运营数据采集</a>
                                    </a-menu-item>
                                    <a-menu-item>
                                        <a href="javascript:;" @click="doEditFinance(record)">财务数据采集</a>
                                    </a-menu-item>
                                </a-menu>
                            </a-dropdown>
                        </span>
                        <span v-else>
                            <a-dropdown style="margin-right:10px;" disabled>
                                <a class="ant-dropdown-link" @click="e => e.preventDefault()" style="color:#c2c2c2;">
                                修改<a-icon type="down" />
                                </a>
                                <a-menu slot="overlay">
                                    <a-menu-item>
                                        <a href="javascript:;" @click="doEditOperation(record)">运营数据采集</a>
                                    </a-menu-item>
                                    <a-menu-item>
                                        <a href="javascript:;" @click="doEditFinance(record)">财务数据采集</a>
                                    </a-menu-item>
                                </a-menu>
                            </a-dropdown>
                        </span>

                        <span v-if="setBtn(record)" @click="showModal(record)">删除</span>
                        <span v-else @click.prevent style="color:#c2c2c2;">删除</span>
                    </a>
                </a-table>
                <!-- 确认删除对话框 -->
                <DelModal v-model="editVisible"
                    @ok="handleOk"
                    @cancel="editVisibleCancel" />
                <!-- 底部分页组件 -->
                <BottomPagination
                    :total="total"
                    @pageChange="pageChange"
                    @sizeChange="sizeChange"
                ></BottomPagination>
            </div>
            <!-- 删除对话框 -->
            <DelModal v-model="batchDeleteVisible"
                :loading="batchDeleteConfirmLoading"
                @ok="batchDeleteHandleOk"
                @cancel="batchDeleteHandleCancel" />
            </div>
    </div>
</template>

<script>
    const columns = [
        {
            title: '序号',
            dataIndex: 'index',
            key: 'index',
            align: 'center',
            ellipsis: true,
            width: 80,
            customRender:(taxe,records,index)=>`${index + 1}`
        },
        {
            title: '2C单均快递成本',
            dataIndex: 'tocOrderExpressCost',
            key: 'tocOrderExpressCost',
            align: 'center',
            ellipsis: true,
        },
        {
            title: '人工成本',
            dataIndex: 'laborCost',
            key: 'laborCost',
            align: 'center',
            ellipsis: true,
            width: 120,
        },
        {
            title: '其他变动成本',
            dataIndex: 'otherVariableCost',
            key: 'otherVariableCost',
            align: 'center',
            ellipsis: true,
            width: 120,
        },
        {
            title: '管理成本',
            dataIndex: 'managementCost',
            key: 'managementCost',
            align: 'center',
            ellipsis: true,
            width: 120,
        },
        {
            title: '其他固定成本',
            dataIndex: 'otherFixedCost',
            key: 'otherFixedCost',
            align: 'center',
            ellipsis: true,
        },
        {
            title: '招商成本',
            dataIndex: 'investmentCost',
            key: 'investmentCost',
            align: 'center',
            ellipsis: true,
        },
        {
            title: '仓老板工资',
            dataIndex: 'managerSalary',
            key: 'managerSalary',
            align: 'center',
            ellipsis: true,
        },
        {
            title: '记账归属',
            dataIndex: 'billTime',
            key: 'billTime',
            scopedSlots: { 
                customRender: 'billTime' 
            },
            align: 'center',
            ellipsis: true,
        },
        {
            title: '修改人',
            dataIndex: 'updateBy',
            key: 'updateBy',
            align: 'center',
            ellipsis: true,
            width: 120,
        },
        {
            title: '修改时间',
            dataIndex: 'updateTime',
            key: 'updateTime',
            align: 'center',
            ellipsis: true,
        },
        { 
            title: '操作', 
            dataIndex: '', 
            key: 'x', 
            scopedSlots: { 
                customRender: 'action' 
            },
            align: 'center',
            width: 150,
        },
    ];

    import { getDate } from '../../../utils/getDate'
    import moment from 'moment'
    import TopSelect from '../../meter/TopSelect'
    import BottomPagination from '../../meter/BottomPagination'
    import DelModal from '@comp/base/delModal'
    // import { getREList, addRE, editRE, deleteRE, } from '@/api/api'
    import { getWarehouse, getWhweeklyList, delWhweekly, addOperation, editOperation, addFinance, editFinance, } from '@/api/api'

    export default {
        name: "IncomeExpend",
        components: {
            TopSelect,
            BottomPagination,
            DelModal   
        },
        data () {
            return {
                data: [],
                columns,
                tableLoading: false,
                selectNumber: 0, // 当前选中数据条数
                selectedRowKeys: [], // 当前选择集合
                deletdBtnShow: false, // 批量删除按钮是否显示
                headquartersId: '', // 总部id
                regionId: '', // 大区id
                cityId: '', // 城市id
                organizeId: '', // 仓库id
                isRegionShow: true,
                isCityShow: true,
                isWareShow: true,
                billTimeSearch: [],
                billTimeBeginSearch: '',
                billTimeEndSearch: '',
                dateFormat: 'YYYY-MM-DD HH:mm:ss',
                pageNo: 1,
                pageSize: 10,
                total: 0,
                visible: false,
                placement: 'right',
                drawerTitle: '新增收支项',
                labelCol: { span: 9 },  
                wrapperCol: { span: 14 },
                other: '',
                billTimeBegin: null,
                billTimeEnd: null,
                precision: 2,
                form: {
                    regionId: '',
                    region: '',
                    cityId: '',
                    city: '',
                    organizeId: '',
                    name: '',
                    billTime: [],
                    tocOrderExpressCost: '',
                    laborCost: '',
                    otherVariableCost: '',
                    managementCost: '',
                    otherFixedCost: '',
                    investmentCost: '',
                    managerSalary: '',
                },
                rules: {
                    tocOrderExpressCost: [
                        { required: true, message: '请输入2C单均快递成本', trigger: 'blur' },
                    ],
                    laborCost: [
                        { required: true, message: '请输入人工成本', trigger: 'blur', },
                    ],
                    otherVariableCost: [
                        { required: true, message: '请输入其他变动成本', trigger: 'blur', },
                    ],
                    managementCost: [
                        { required: true, message: '请输入管理成本', trigger: 'blur', },
                    ],
                    otherFixedCost: [
                        { required: true, message: '请输入其他固定成本', trigger: 'blur', },
                    ],
                    investmentCost: [
                        { required: true, message: '请输入招商成本', trigger: 'blur', },
                    ],
                    managerSalary: [
                        { required: true, message: '请输入仓老板工资', trigger: 'blur', },
                    ],
                },
                validStatus: true, // 当前表单验证状态，true表示成功，false表示失败
                editVisible: false, // 确认删除对话框
                batchDeleteVisible: false, // 批量删除
                batchDeleteConfirmLoading: false,
                nameList: [],
                regionList: [],
                cityList: [],
                warehouseList: [],
                regionName: '', // 大区名称
                cityName: '', // 城市名称
                warehouseName: '', // 仓库名称
                addMode: true,
                disabled: false,
                id: '',
                ids: '',
                key: '',
            }
        },
        created() {
        },
        methods: {
            getDate,
            moment,
            // 选择框过滤
            filterOption(input, option) {
                return (
                    option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
                );
            },
            // 搜索
            onSearch() {
                if( (this.regionId == '' || this.regionId == undefined) || (this.cityId == '' || this.cityId == undefined) || (this.organizeId == '' || this.organizeId == undefined) ){
                    this.$message.warning('搜索时必须先选择大区、城市和仓库！')
                }else{
                    this.getWhweeklyList()
                }
                this.selectNumber = 0
                this.selectedRowKeys = []
                this.deletdBtnShow = false
            },
            // 重置
            onReset() {
                this.$refs.topSelect.onReset()
                this.billTimeSearch = []
                this.billTimeBeginSearch = ''
                this.billTimeEndSearch = ''
                this.pageSize = 10
                this.pageNo = 1
                this.total = 0
                this.data = []
                this.selectNumber = 0
                this.selectedRowKeys = []
                this.deletdBtnShow = false
            },
            // 获取列表数据
            getWhweeklyList() {
                let params = {
                    organizeId: this.organizeId,
                    billTimeBegin: this.billTimeBeginSearch,
                    billTimeEnd: this.billTimeEndSearch,
                    pageSize: this.pageSize,
                    pageNo: this.pageNo,
                    delFlag: 0,
                }
                this.tableLoading = true
                getWhweeklyList(params).then((res)=>{
                    this.tableLoading = false
                    if(res.success){
                        this.data = res.result.records
                        this.total = res.result.total
                    }else{
                        this.$message.warning(res.message)
                    }
                })
            },
            
            handleChange(value) {
                console.log(`selected ${value}`);
            },
            // 选中
            onSelectChange(selectedRowKeys) {
                this.selectedRowKeys = selectedRowKeys
                this.selectNumber = selectedRowKeys.length
                if(this.selectedRowKeys.length > 0){
                    this.deletdBtnShow = true
                }else{
                    this.deletdBtnShow = false
                }
            },
            // 清空选中
            clearSelect() {
                this.selectNumber = 0
                this.selectedRowKeys = []
                this.deletdBtnShow = false
            },
            // 获取当前总部id
            getHeadId(data) {
                this.headquartersId = data
            },
            // 获取当前大区id
            getRegionId(data) {
                this.regionId = data
                this.form.regionId = data
                this.$refs.topSelect.clearRegion()
            },
            // 获取当前城市id
            getCityId(data) {
                this.cityId = data
                this.form.cityId = data
                this.$refs.topSelect.clearCity()
            },
            // 获取当前仓库id
            getWareId(data) {
                this.organizeId = data
                this.form.organizeId = data

                let params = {
                    cityIds: this.cityId
                }
                getWarehouse(params).then((res)=>{
                    if(res.success){
                        this.warehouseList = res.result.organizeOrgList
                        for(var item of this.warehouseList){
                            if(this.organizeId == item.id){
                                this.form.whCode = item.code
                            }
                        }
                    }
                })

                this.pageNo = 1
                this.pageSize = 10
            },
            // 获取当前页数、条数
            pageChange(data1, data2) {
                this.pageNo = data1
                this.pageSize = data2
                this.getWhweeklyList()
            },
            // 获取当前页数、条数
            sizeChange(data1, data2) {
                this.pageNo = data1
                this.pageSize = data2
                this.getWhweeklyList()
            },
            // 创建时间
            billTimeChange(value, dateString) {
                this.billTimeSearch = value
                this.billTimeBeginSearch = dateString[0]
                this.billTimeEndSearch = dateString[1]
            },
            billTimeOk(value) {
                console.log('onOk: ', value);
            },
            // 新增
            handleMenuClick(e) {
                if( (this.regionId == '' || this.regionId == undefined) || (this.cityId == '' || this.cityId == undefined) || (this.organizeId == '' || this.organizeId == undefined) ){
                    this.$message.warning('新增时必须先选择大区、城市和仓库！')
                    return
                }

                if(this.validStatus === false) {
                    this.$refs.ruleForm.resetFields()
                }

                this.visible = true;
                this.key = e.key
                this.addMode = true
                if(this.key == 'YY'){
                    this.drawerTitle = '新增运营数据采集'
                }else{
                    this.drawerTitle = '新增财务数据采集'
                }

                this.form.tocOrderExpressCost = ''
                this.form.laborCost = ''
                this.form.otherVariableCost = ''
                this.form.managementCost = ''
                this.form.otherFixedCost = ''
                this.form.investmentCost = ''
                this.form.managerSalary = ''
                
                try {
                    let time = getDate()
                    let format = 'YYYY-MM-DD HH:mm:ss'
                    this.form.billTime = [moment(time[0], format), moment(time[1], format)]
                    this.billTimeBegin = time[0]
                    this.billTimeEnd = time[1]
                } catch {}
            },
            onClose() {
                this.visible = false;
            },
            // 修改按钮置灰
            setBtn(record) {
                var timestamp1 = new Date().getTime()
                var timestamp2 = new Date(record.billTimeEnd).getTime()
                
                if(timestamp1 < timestamp2){
                    return true
                }else{
                    return false
                }
            },
            // 修改
            doEditOperation(record) {
                this.key = "YY"
                this.visible = true;
                this.drawerTitle = '修改运营数据采集'
                this.addMode =false
                this.form.organizeId = record.organizeId
                this.form.whCode = record.whCode
                this.form.tocOrderExpressCost = record.tocOrderExpressCost
                this.form.laborCost = record.laborCost
                this.form.otherVariableCost = record.otherVariableCost
                this.form.managementCost = record.managementCost
                this.form.otherFixedCost = record.otherFixedCost
                this.billTimeBegin = record.billTimeBegin
                this.billTimeEnd = record.billTimeEnd
                this.form.billTime = [
                    this.moment(`${record.billTimeBegin + ' 00:00:00'}`, 'YYYY-MM-DD HH:mm:ss'),
                    this.moment(`${record.billTimeEnd + ' 23:59:59'}`, 'YYYY-MM-DD HH:mm:ss'),
                ]

                if(this.validStatus === false) {
                    this.$refs.ruleForm.resetFields()
                }
            },
            doEditFinance(record) {
                this.key = "CW"
                this.visible = true;
                this.drawerTitle = '修改财务数据采集'
                this.addMode =false
                this.form.organizeId = record.organizeId
                this.form.whCode = record.whCode
                this.form.investmentCost = record.investmentCost
                this.form.managerSalary = record.managerSalary
                this.billTimeBegin = record.billTimeBegin
                this.billTimeEnd = record.billTimeEnd
                this.form.billTime = [
                    this.moment(`${record.billTimeBegin + ' 00:00:00'}`, 'YYYY-MM-DD HH:mm:ss'),
                    this.moment(`${record.billTimeEnd + ' 23:59:59'}`, 'YYYY-MM-DD HH:mm:ss'),
                ]

                if(this.validStatus === false) {
                    this.$refs.ruleForm.resetFields()
                }
            },
            // 表单
            onSubmit() {
                if(this.key == 'YY'){
                    this.$refs.ruleForm.validate(valid => {
                        if (valid) {
                            this.validStatus = true

                            let params = {
                                organizeId: this.form.organizeId,
                                whCode: this.form.whCode,
                                billTimeBegin: this.billTimeBegin,
                                billTimeEnd: this.billTimeEnd,
                                tocOrderExpressCost: this.form.tocOrderExpressCost,
                                laborCost: this.form.laborCost,
                                otherVariableCost: this.form.otherVariableCost,
                                managementCost: this.form.managementCost,
                                otherFixedCost: this.form.otherFixedCost,
                            }

                            if(this.addMode){ // 新增
                                
                                addOperation(params).then((res)=>{
                                    if(res.success){
                                        this.visible = false
                                        this.$message.success('保存成功！')
                                        if( this.regionId != '' && this.cityId != '' && this.organizeId != '' ){
                                            this.getWhweeklyList()
                                        }
                                    }else{
                                        this.$message.warning(res.message)
                                    }
                                })
                            }else{ // 修改
                                
                                editOperation(params).then((res)=>{
                                    if(res.success){
                                        this.visible = false
                                        this.$message.success('保存成功！')
                                        this.getWhweeklyList()
                                    }else{
                                        this.$message.warning(res.message)
                                    }
                                })
                            }
                        } else {
                            this.validStatus = false
                            return false;
                        }
                    });
                }else{
                    this.$refs.ruleForm.validate(valid => {
                        if (valid) {
                            this.validStatus = true

                            let params = {
                                organizeId: this.form.organizeId,
                                whCode: this.form.whCode,
                                billTimeBegin: this.billTimeBegin,
                                billTimeEnd: this.billTimeEnd,
                                investmentCost: this.form.investmentCost,
                                managerSalary: this.form.managerSalary,
                            }

                            if(this.addMode){ // 新增
                                
                                addFinance(params).then((res)=>{
                                    if(res.success){
                                        this.visible = false
                                        this.$message.success('保存成功！')
                                        if( this.regionId != '' && this.cityId != '' && this.organizeId != '' ){
                                            this.getWhweeklyList()
                                        }
                                    }else{
                                        this.$message.warning(res.message)
                                    }
                                })
                            }else{ // 修改
                                
                                editFinance(params).then((res)=>{
                                    if(res.success){
                                        this.visible = false
                                        this.$message.success('保存成功！')
                                        this.getWhweeklyList()
                                    }else{
                                        this.$message.warning(res.message)
                                    }
                                })
                            }
                        } else {
                            this.validStatus = false
                            return false;
                        }
                    });
                }
                
            },
            cancelForm() {
                this.visible = false;
            },
            // 确认删除对话框
            showModal(record) {
                this.editVisible = true;
                this.ids = record.id
            },
            handleOk(e) {
                this.editVisible = false;
                let params = {
                    ids: this.ids,
                }
                delWhweekly(params).then((res)=>{
                    if(res.success){
                        this.visible = false
                        this.$message.success('删除成功！')
                        this.getWhweeklyList()
                    }else{
                        this.$message.warning(res.message)
                    }
                })
            },
            // 批量删除
            batchDelete() {
                this.batchDeleteConfirmLoading = false;
                if(this.selectedRowKeys.length <= 0){
                    this.$message.warning('请先勾选需要删除的项！')
                    return
                }
                this.batchDeleteVisible = true
                this.ids = this.selectedRowKeys.join(',')
            },
            batchDeleteHandleOk(e) {
                this.batchDeleteConfirmLoading = true;
                let params = {
                    ids: this.ids,
                }
                delWhweekly(params).then((res)=>{
                    if(res.success){
                        this.batchDeleteVisible = false;
                        this.batchDeleteConfirmLoading = false;
                        this.selectNumber = 0
                        this.selectedRowKeys = []
                        this.deletdBtnShow = false
                        this.$message.success('删除成功！')
                        this.getWhweeklyList()
                    }else{
                        this.$message.warning(res.message)
                    }
                })
            },
            batchDeleteHandleCancel(e) {
                this.batchDeleteVisible = false;
            },
            editVisibleCancel(e){
                this.editVisible = false
            }

        },
        
    }
</script>

<style lang="less" scoped>
    .incomeExpend{
        width: 100%;
        padding: 0 10px 10px 10px;
        font-style: Microsoft YaHei;
        background: #ffffff;
        box-sizing: border-box;
        .top_operation{
            margin-bottom: 10px;
            overflow: hidden;
            .every_operation{
                float: left;
                margin-top: 10px;
                margin-right: 20px;
                span{
                    display: inline-block;
                    width: 85px;
                }
            }
            .button_div{
                float: left;
                margin-top: 10px;
            }
        }
        .select_number{
            width: 100%;
            height: 36px;
            padding-left: 20px;
            margin-bottom: 10px;
            box-sizing: border-box;
            background: rgba(57, 72, 103, .22);
            line-height: 36px;
            .number_span{
                color: #ffffff;
                margin-right: 30px;
                b{
                    color: #394867;
                    margin: 0 15px;
                }
            }
            .clear_span{
                cursor: pointer;
                color: #394867;
            }
        }
        .add_btn{
            margin-bottom: 10px;
        }
        .data_source_list{
            h3{
                font-weight: bold;
            }
            .data_pagination{
                width: 100%;
                height: 32px;
                margin: 20px 0 10px 0;
            }
        }

    }
</style>